package meteocal.gui.security;

import java.io.Serializable;
import javax.ejb.EJB;
import javax.inject.Named;
import javax.enterprise.context.RequestScoped;
import javax.enterprise.context.SessionScoped;
import meteocal.business.security.boundary.UserManager;
import meteocal.business.security.entity.User;

/**
 *
 * @author luana
 */

@Named(value = "userBean")
@RequestScoped
public class UserBean implements Serializable{
    
    private static final long serialVersionUID = 1L;

    
    @EJB
    UserManager um;
    
    private User user;
    private LoginBean lb;
    private boolean canModify;

    public UserBean() {
        lb = new LoginBean();
    }
 
    
    
    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    
    public String getUsername() {
        return um.getLoggedUser().getUsername();
    }    
    
    public String getCity() {
        return um.getLoggedUser().getCity();
    }
   
    public String getPassword() {
        return um.getLoggedUser().getPassword();
    }

    public String getEmail() {
        return um.getLoggedUser().getEmail();
    }

    public String getName() {
        return um.getLoggedUser().getName();
    }

    public String getPhonenumber() {
        return um.getLoggedUser().getPhonenumber();
    }

    public String getAvatar() {
        return um.getLoggedUser().getAvatar();
    }
    
    public String modifyUser(){
        um.updateUser(user);
        return "main-page?faces-redirect=true";
    }
    
    public String deleteUser(){
            um.delete(user);
            return lb.logout();
    }

    public boolean isCanModify() {
        return canModify;
    }  
    
    public String modifyCalendar(){
        if(user.isPrivacyLevel() == false){
            user.setPrivacyLevel(true);
            um.updateUser(user);
            return "main-page?faces-redirect=true"; 
        }
        else{
            user.setPrivacyLevel(false);
            um.updateUser(user);
            return "main-page?faces-redirect=true";
        }
        
    }
   
}
   
    
    

